package DataAccess;

import java.sql.Connection;
import java.sql.DriverManager;
import javax.naming.InitialContext;
import javax.sql.DataSource;

/**
 *
 * @author reynier
 */
public class DBManager {

    private static DBManager _instance = new DBManager();

    private DBManager() {
    }

    public static DBManager getInstance() {
        return _instance;
    }

    public Connection getConnection() throws Exception {
        return getDatabaseConnection();
    }

    private Connection getDatabaseConnection() throws Exception {
        Connection conn = null;

        try {
             DataSource ds = (DataSource) new InitialContext().lookup("jdbc/grs");
             conn = ds.getConnection();

        } catch (Exception e) {
            System.out.println("Exception: Unable to open connection to db: " + e.getMessage());
            throw e;
        }
        return conn;
    }
}
